﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;

using CloudSoft.Workflows;

namespace ERPStore.NewsLetters.Workflows.Activities
{

	public sealed class GetEmailListSourceProvider : CodeActivity
	{
		public InArgument<Models.Campaign> Campaign { get; set; }
		public OutArgument<Services.IEmailListSourceProvider> RecipientListProvider { get; set; }

		protected override void Execute(CodeActivityContext context)
		{
			var campaign = context.GetValue(this.Campaign);
			var newsLetterService = context.GetService<Services.NewsLettersService>();

			var rlp = newsLetterService.GetEmailListProvider(campaign);
			if (rlp != null)
			{
				context.ReportProgress(string.Format("EmailListSourceProvider resolved : {0}", rlp.DisplayName));
			}
			else
			{
				context.ReportProgress("no EmailListSourceProvider was resolved");
			}

			context.SetValue(this.RecipientListProvider, rlp);
		}
	}
}
